<?php 
// +----------------------------------------------------------------------
// | OneKeyAdmin [ Believe that you can do better ]
// +----------------------------------------------------------------------
// | Copyright (c) 2020-2023 http://onekeyadmin.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: MUKE <513038996@qq.com>
// +----------------------------------------------------------------------
declare (strict_types = 1);

namespace app\admin\middleware;

use app\admin\model\Admin;
/**
 * 登录检测
 */
class LoginCheck
{
    /**
     * 不需要检查的类
     * @var noVerification
     */
    protected $ignoreCheckClass = [
        'login'
    ];
    
    public function handle($request, \Closure $next)
    {
        $request->userInfo = session('admin');
        if (! in_array($request->class, $this->ignoreCheckClass)) {
            // 登录检查
            if (empty($request->userInfo)) {
                return $request->isPost() ? json(['status'=>'login', 'message'=>'登录状态过期失效！']) : redirect(admin_url('login/index'));
            }
        }
        // 下一步
        return $next($request);
    }
}